package wei.xinya.springWeb.service.impl;

import org.springframework.stereotype.Service;
import wei.xinya.springWeb.dao.StudentDao;
import wei.xinya.springWeb.entity.Student;
import wei.xinya.springWeb.service.StudentService;

import javax.annotation.Resource;

@Service
public class StudentServiceImpl implements StudentService {

    @Resource
    private StudentDao studentDao;

    @Override
    public void addStudent(Student student) {
        Integer studentId = student.getId();
        if (studentId != null && findStudentById(studentId) != null) {
            throw new RuntimeException("id已存在");
        }

        studentDao.insertStudent(student);
    }

    @Override
    public Student findStudentById(Integer id) {
        return studentDao.selectById(id);
    }

}
